using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.Reflection;
using System.Windows.Forms;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	public sealed class modEditChapter
	{
		private static clsProject cProject;

		public static bool EditChapter(ref clsProject ProjectClass, int ChID, int WhichTab = 0)
		{
			bool result = false;
			try
			{
				_ = modVariables.EnableCollab;
				cProject = ProjectClass;
				frmEditChapter frmEditChapter = new frmEditChapter(ref cProject, ChID);
				frmEditChapter.PrevChapter += PrevChapter;
				frmEditChapter.NextChapter += NextChapter;
				if (frmEditChapter.ShowDialog() == DialogResult.OK)
				{
					result = true;
				}
				frmEditChapter.PrevChapter -= PrevChapter;
				frmEditChapter.NextChapter -= NextChapter;
				return result;
			}
			catch (Exception ex)
			{
				ProjectData.SetProjectError(ex);
				Exception ex2 = ex;
				clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
				ProjectData.ClearProjectError();
				return result;
			}
		}

		private static void PrevChapter(int CurrentID)
		{
			int num = cProject.Chapters.IndexFromID(CurrentID);
			num = ((num != 1) ? (num - 1) : cProject.Chapters.Count);
			int chID = cProject.Chapters.IDFromIndex(num);
			EditChapter(ref cProject, chID);
		}

		private static void NextChapter(int CurrentID)
		{
			int num = cProject.Chapters.IndexFromID(CurrentID);
			num = ((num == cProject.Chapters.Count) ? 1 : (num + 1));
			int chID = cProject.Chapters.IDFromIndex(num);
			EditChapter(ref cProject, chID);
		}

		public static bool AddEditChapters(ref clsProject cProject, bool ShowChooser)
		{
			if (new frmList(ref cProject, eRecord.eChapter).ShowDialog(ShowChooser) == DialogResult.OK)
			{
				return true;
			}
			bool result = default(bool);
			return result;
		}
	}
}
